/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.jmmarca.xxx;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import android.widget.VideoView;
import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;

class Tarefa extends TimerTask {

    private VideoView mVideoView2;
    private Map<Integer, String> map_comando_basico = new HashMap<Integer, String>();
    private Integer situacaoAparelho = 0;
    private Integer ultimoSituacaoAparelho = 0;
    private Context context = null;


    public Tarefa(Context context, VideoView mVideoView2) {
        this.mVideoView2 = mVideoView2;
        this.context = context;
        map_comando_basico.put(0, "PARADO");
        map_comando_basico.put(1, "NORMAL");
        map_comando_basico.put(2, "DESCER");
        map_comando_basico.put(3, "SUBIR");
        
        
    }



    public void run() {
        Integer pos = this.mVideoView2.getCurrentPosition();
        int posf = (pos / 1000);
        if (!this.mVideoView2.isPlaying()) {
            situacaoAparelho = 0;
        } else {

            if (posf > 0 && posf < 40 && !situacaoAparelho.equals(1)) {
                situacaoAparelho = 1;
            } else if (posf > 40 && posf <= 90 && !situacaoAparelho.equals(2)) {
                situacaoAparelho = 2;
            } else if (posf > 90 && !situacaoAparelho.equals(3)) {
                situacaoAparelho = 3;
            }
        }
        if(!ultimoSituacaoAparelho.equals(situacaoAparelho)){
//            mEmulatorView.set
            Log.i("CMD", "ENVIANDO COMANDO: "+map_comando_basico.get(situacaoAparelho));
            ultimoSituacaoAparelho =situacaoAparelho;
        }
        
        Log.w("LOG", String.valueOf(pos) + " - Situacao: " + this.situacaoAparelho + " - Sec: " + String.valueOf(posf));

        
    }
}